package chap7;

/**
 * @author oldliu
 * @since 1.0
 */
public class BubbleSort {
    public static void main(String[] args) {
        //按照从小到大的顺序
        int ar[]={1,4,24,6,32,23,15,14,5};
        int b[]=new int[ar.length];
        //初始化b这个数组，记录原来的位置
        for(int i=0;i<b.length;i++){
            b[i]=i;
        }
        System.out.print("排序之前：");
        for (int i = 0; i <ar.length; i++) {
            System.out.print(ar[i]+" ");
        }
        System.out.println();
        int temp=0;
        for(int i=0;i<ar.length-1;i++){
            for(int j=0;j<ar.length-1-i;j++){
                if(ar[j]>ar[j+1]){
                    //把数组的j和j+1调换
                    temp=ar[j];
                    ar[j]=ar[j+1];
                    ar[j+1]=temp;
                }
            }
        }
        System.out.print("排序之后：");
        for (int i = 0; i <ar.length; i++) {
            System.out.print(ar[i]+" ");
        }
        System.out.println();
    }
}
